<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
	<jsp:include page="/include.jsp"/>
	<script type="text/javascript">
	
	$(function(){
		//新增按纽绑定事件
		$('#add').bind('click',doAdd);
		//渲染问题级别下拉框
		$('#problemLevel').combobox({
			url:'${pageContext.request.contextPath}/problemmgr/problemAction!getDic.action?codeType=warnLevel&method=list',  
   			valueField:'codeValue',  
  	 		textField:'codeName',
  	 		panelHeight:'auto',
  	 		editable:false,
  	 		onLoadSuccess:function(){
  				//不让第一条为默认选择项
  				$('#problemLevel').combobox('unselect',0);
  				$('#problemLevel').combobox('setValue',null);
  			}
		});
		//渲染问题来源下拉框
		$('#problemOrigin').combobox({
			url:'${pageContext.request.contextPath}/problemmgr/problemAction!getDic.action?codeType=requireSrc&method=list',  
   			valueField:'codeValue',  
  	 		textField:'codeName',
  	 		panelHeight:'auto',
  	 		editable:false,
  	 		onLoadSuccess:function(){
  				//不让第一条为默认选择项
  				$('#problemOrigin').combobox('unselect',0);
  				$('#problemOrigin').combobox('setValue',null);
  			}
		});
		//日期组件
		$('#discoveryTime').my97({
			dateFmt:'yyyy-MM-dd',
			startDate:[{
				doubleCalendar:false,
				isShowWeek:false,
				isShowClear:false,
				readOnly:true
				 
			}]
		});
		//查询表格数据
		getDatagridByID();
	});
	
	//查询数据方法
	function getDatagridByID()
	{
		$("#problemTab").datagrid({
			url : '${pageContext.request.contextPath}/problemmgr/problemAction!getProblemByID.action',
			queryParams:serializeObject($('#search_form')),
			fit:true,
			border:false,
			fitColumns:true,
			pagination:true,
			pageList:[10,20,30],
			rownumbers:true,
			singleSelect:false,
			pagePosition:'bottom',
			autoRowHeight:true,
			rownumbers:false,
			sortName:'discoveryTime',
			sortOrder:'desc',
			striped:true,
			columns:[[  {field:'problemId',checkbox:true},
			            {field:'status',hidden:true},
			            {field:'title',title:'问题主题',width:100,align:'left',sortable:true,formatter:function(value,rowData,rowIndex){
			            	if(rowData.title!=undefined){
			            		  return '<div  onmouseover="onMouseOverName(this)"  onmouseout="onMouseOutName(this)" onclick="doDetail('+rowData.problemId+')" style="color:#2b76b7;cursor:pointer;width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;" title="'+rowData.title+'">'+rowData.title+'</div>';
			            		  }

								}},
			            
						{field:'problemLevel',title:'问题级别',width:60,align:'center',sortable:true,formatter:function(value,rowData,rowIndex){
							if(rowData.problemLevel=="0"){
								   return "<span style='color:#7aba42'>提示</span>";
								  }else if(rowData.problemLevel=="1"){
								  	return "<span style='color:#8cbeed'>一般告警</span>";
								  }else if(rowData.problemLevel=="2"){
								  	return "<span style='color:#ff9200'>重要告警</span>";
								  }else if(rowData.problemLevel=="3"){
								  	return "<span style='color:#ec0101'>严重告警</span>";
								  }
								}},				
						{field:'aaa',title:'当前状态',width:60,align:'center',formatter:function(value,rowData,rowIndex){
							if(rowData.status=="0"){
						   return "<span>未处理</span>";
						  }else if(rowData.status=="1"){
						  	return "<span>处理中</span>";
						  }else if(rowData.status=="2"){
						  	return "<span>待审核</span>";
						  }else if(rowData.status=="3"){
						  	return "<span>处理完毕</span>";
						  }
						}},
						{field:'discoveryTime',title:'发生时间',width:120,align:'center'},
						{field:'responsibler',title:'责任人',width:60,align:'center'},
						{field:'handler',title:'处理人',width:60,align:'center'},
						{field:'dsafd',title:'操作',width:80,align:'left',formatter:function(value,rowData,rowIndex){
							if(rowData.status=='0'){
								return '<span  style="cursor:pointer" onclick="deleteUndealAlert()"><img onclick="deleteAlert()" src="${pageContext.request.contextPath}/images/icons/delete.png" title="删除" alt="删除"/>删除</span>';
							}else if(rowData.status=='1'){
								return '<span  style="cursor:pointer" onclick="deleteDealingAlert()"><img onclick="deleteAlert()" src="${pageContext.request.contextPath}/images/icons/delete.png" title="删除" alt="删除"/>删除</span>';
							}else if(rowData.status=='2'){
								return '<span  style="cursor:pointer" onclick="deleteUndealAlert()"><img onclick="deleteAlert()" src="${pageContext.request.contextPath}/images/icons/delete.png" title="删除" alt="删除"/>删除</span>';
							}else if(rowData.status=='3'){
								if(rowData.knowledgeSatus=='1'){ 
									return '<span  style="cursor:pointer" onclick="doDelete('+rowData.problemId+',\''+rowData.responsibler+'\')"><img onclick="doDelete('+rowData.problemId+',\''+rowData.responsibler+'\')" src="${pageContext.request.contextPath}/images/icons/delete.png" title="删除" alt="删除"/>删除</span>';
								}else{
									return '<span  style="cursor:pointer" onclick="doDelete('+rowData.problemId+',\''+rowData.responsibler+'\')"><img onclick="doDelete('+rowData.problemId+',\''+rowData.responsibler+'\')" src="${pageContext.request.contextPath}/images/icons/delete.png" title="删除" alt="删除"/>删除</span>'
									 +'&nbsp;&nbsp;<span  style="cursor:pointer" onclick="doAddKnowledge('+rowData.problemId+',\''+rowData.responsibler+'\')"><img onclick="doAddKnowledge('+rowData.problemId+',\''+rowData.responsibler+'\')" src="${pageContext.request.contextPath}/images/icons/trans_knowled.png" title="转入知识库" alt="转入知识库"/>转入知识库</span>';
								}
							}
							
						}}
					]],
			toolbar:'#problem_toobar'
		});
	}
	
	//分页查询
	function doQuery()
	{
		var dataGridOptions=$('#problemTab').datagrid('options');
		if($('#search_form').form('validate'))
		{
			dataGridOptions.queryParams=serializeObject($('#search_form'));
			$('#problemTab').datagrid(dataGridOptions);
			$('#problemTab').datagrid('load');
		}
	}
	
//转入知识库操作
function doAddKnowledge(problemId){
	var pars="problemId="+problemId;
    window.top.$('<div/>').dialog({
		href:'${pageContext.request.contextPath}/problemmgr/problemAction!toShowKnowledgePage.action?'+pars,
		top:($(window).height()-250)*0.5,
	    left:($(window).width()-300)*0.5,
		width:700,
		modal:true,
		title:'转入知识库',
		buttons : [{
			text:'确 定',
			iconCls:'',
			handler:function(){
				var d=window.top.$(this).closest('.window-body');
				var flag = window.top.addKnowledge();
				if(flag=="1"){
				window.top.$('#problem_edit_form').form('submit',{
					url:'${pageContext.request.contextPath}/knowledgebase/knowlegeAction!addKnowledge.action',
					success:function(result){
						try {
							var r = $.parseJSON(result);
							$.messager.show({
								title : '提示',
								msg : r.returnMsg
							});
							if (r.returnFlag) {
								d.dialog('destroy');
								$('#search_form').form('clear');
								getDatagridByID();
							}
							
						} catch (e) {
							$.messager.alert('提示', result);
						}
						}
					});
			  }
			}
			}],
		onClose:function(){
			window.top.$(this).dialog('destroy');
		}
	});
}
//显示问题详细信息界面
function doDetail(problemId){		
        var pars="problemId="+problemId;
        window.top.$('<div/>').dialog({
			href:'${pageContext.request.contextPath}/problemmgr/problemAction!getProblemDetail.action?'+pars,
			top:($(window).height()-250)*0.5,
		    left:($(window).width()-300)*0.5,
			width:730,
			modal:true,
			title:'问题信息',
			buttons : [ {
				text : '关闭',
				iconCls : '',
				handler : function() {
					window.top.$(this).closest('.window-body').dialog('destroy');
				}
			} ],
			onClose:function(){
				window.top.$(this).dialog('destroy');
			}
		});
        $('#search_form').form('clear');
	}
	
	//修改问题
	function editProblem(problemId){		
        var pars="problemId="+problemId;
        window.top.$('<div/>').dialog({
			href:'${pageContext.request.contextPath}/problemmgr/problemAction!getProblemDetailByID.action?'+pars,
			top:($(window).height()-250)*0.5,
		    left:($(window).width()-300)*0.5,
			width:600,
			modal:true,
			title:'修改问题',
			buttons:[{
				text:'保 存',
				iconCls:'icon-add',
				plain:true,
				handler:function(){
					var d=window.top.$(this).closest('.window-body');
					window.top.$('#problem_edit_form').form('submit',{
						url:'${pageContext.request.contextPath}/problemmgr/problemAction!updateProblem.action',
						data:pars,
						success:function(result){
							try {
								var r = $.parseJSON(result);
								$.messager.show({
									title : '提示',
									msg : r.returnMsg
								});
								if (r.returnFlag) {
									d.dialog('destroy');
									pars='';
								//	getDatagridByID();
								window.location.reload();
								}
								
							} catch (e) {
								$.messager.alert('提示', result);
							}
							}
						});
					}
				}],
			onClose:function(){
				window.top.$(this).dialog('destroy');
			}
		});
        
	}
	
	//单个问题删除
	function doDelete(problemId,responsibler){
		if('${userId}'!=(responsibler)){
			window.top.$.messager.alert('提示','没有删除此问题的权限！');
			return;
		}
		
		 $.messager.confirm('删除确认', '删除问题将同时删除该问题下的回复与文件信息,确定要删除该条记录吗？',function(r){
			if(r){
				var pars="problemId="+problemId;
				$.ajax({
					 url :'${pageContext.request.contextPath}/problemmgr/problemAction!deleteProblem.action',
					 data:pars,
					 dataType :'json',
					 success : function(r1){ 
					       $.messager.show({
								title:'提示',
								msg:r1.returnMsg,
								showType:'slide'
							});
					       getDatagridByID();	
					 }
		         });  
				$('#search_form').form('clear');
				getDatagridByID();	
			}
		 });
	}
	
	
	//批量删除
	function deleteProblem(){
		var problemId="";
		var obj=$("#problemTab").datagrid("getChecked");
        if(null!=obj){
        	for(var idx=0;idx<obj.length;idx++){
        		if('${userId}'!=obj[idx].responsibler){
        			window.top.$.messager.alert('提示','没有删除此问题的权限！');
        			return;
        		}
        		if(obj[idx].status=='0'){
        			window.top.$.messager.alert('提示','没有处理完毕的问题不能删除！');
        			return;
        		}else if(obj[idx].status=='1'){
        			window.top.$.messager.alert('提示','没有处理完毕的问题不能删除！');
        			return;
        		}else if(obj[idx].status=='2'){
        			window.top.$.messager.alert('提示','没有处理完毕的问题不能删除！');
        			return;
        		}
        		problemId+=obj[idx].problemId+";";
        	}
        	problemId=problemId.substring(0,problemId.length-1);
            if(problemId==''){
            	window.top.$.messager.alert('提示','请至少选择一个对象进行删除！');
            	return;
            }  	
        
        	
        }else{
        	window.top.$.messager.alert('提示','请至少选择一个对象进行删除！');
        	return;
        }
        $.messager.confirm('删除确认', '删除问题将删除该问题下的所有的反馈和文件,确定要删除该条记录吗？', function(r){
			if (r){
				var pars="problemId="+problemId;
				$.ajax({
					 url :'${pageContext.request.contextPath}/problemmgr/problemAction!deleteProblem.action',
					 data:pars,
					 dataType :'json',
					 success : function(r1){ 
					       $.messager.show({
								title:'提示',
								msg:r1.returnMsg,
								showType:'slide'
							});
					       getDatagridByID();
					 }
		                   });  
					$('#search_form').form('clear');
					getDatagridByID();
				   }
		 });       
        
		
	}
	//新增
    function doAdd(){
    	window.top.$('<div/>').dialog({
			href:'${pageContext.request.contextPath}/problemmgr/problemAction!toAddKnolwdgePage.action',
			top:($(window).height()-250)*0.5,
		    left:($(window).width()-500)*0.5,
			width:730,
			modal:true,
			title:'新增问题',
			buttons : [ {
				id:'btnSave',
				text:'保 存',
				iconCls:'',
				handler : function() {
					var d = window.top.$(this).closest('.window-body');
					window.top.$('#problem_main_form').form('submit', {
						url : '${pageContext.request.contextPath}/problemmgr/problemAction!addProblem.action',
						success : function(result) {
							try {
								var r = $.parseJSON(result);
								$.messager.show({
									title : '提示',
									msg : r.returnMsg
								});
								if (r.returnFlag) {
									d.dialog('destroy');
									$('#search_form').form('clear');
									getDatagridByID();
								}
							} catch (e) {
								$.messager.alert('提示', result);
							}
						}
					});
				}
			} ],
			onClose:function(){
				window.top.$(this).dialog('destroy');
			}
		});
    }
	
	
    function deleteUndealAlert(){
    	window.top.$.messager.alert('提示','未处理的问题不能删除！');
    }
    
    function deleteDealingAlert(){
    	window.top.$.messager.alert('提示','处理中的问题不能删除！');
    }
    
    function deleteUndealAlert(){
    	window.top.$.messager.alert('提示','未审核的问题不能删除！');
    }
    
    //重置方法
    function resetData(){
    	$("#title").val('');
    	$('#problemLevel').combobox("setValue",null);
    	$("#status").combobox("setValue","");
    	$('#problemOrigin').combobox('setValue',null);
    	$('#keyWord').val('');
    	$('#discoveryTime').val('');
    }
	</script>
</head>

<body class="easyui-layout">

<form id="search_form" method="post">
  <div data-options="region:'north'" style="height:80px;border-bottom:none;border-top:none;" >
		<table cellpadding="0" cellspacing="0" height="100%"  width="100%"  >
			<tbody>
				<tr>
					<td style="width:10%;text-align:right;" nowrap="nowrap">
						<label for="reportnameQ">问题主题：</label>
					</td>
					<td style="width:15%;text-align:left;" nowrap="nowrap">
						<input name="title" id="title" type="text" class="easyui-validatebox" validType="specialCharFilter('title')" class="easyui-validatebox" type="text"/> 
					</td>
					
					<td style="width:10%;text-align:right;" nowrap="nowrap">
						<label for="reportnameQ">问题级别：</label>
					</td>
					<td style="width:15%;text-align:right;" nowrap="nowrap">
						<input id="problemLevel" readonly="readonly" class="easyui-combobox" panelHeight='auto' name="problemLevel"  style="width: 180px"/>
					</td>
					<td style="width:10%;text-align:right;" nowrap="nowrap">
						<label for="reportnameQ">状态：</label>
					</td>
					<td style="width:15%;text-align:right;" nowrap="nowrap">
						<select id="status" class="easyui-combobox" data-options="editable:false" name="status" class="easyui-combobox" panelHeight='auto' style="width:180px;">
							<option value="">全部</option>
							<option value="0">未处理</option>
							<option value="1">处理中</option>
							<option value="2">待审核</option>
							<option value="3">处理完毕</option>
						</select>
					</td>
					<td style="width:10%;text-align:right;" nowrap="nowrap">
						<label for="reportnameQ">问题来源：</label>
					</td>
					<td style="width:15%;text-align:left;padding-right:35px" nowrap="nowrap">
						<input id="problemOrigin"  name="problemOrigin" style="width: 180px"/>
					</td>
				</tr>
				<tr>
					<td style="width:10%;text-align:right;" nowrap="nowrap">
						<label for="reportnameQ">关键字：</label>
					</td>
					<td style="width:15%;text-align:right;" nowrap="nowrap">
						<input id="keyWord" name="keyWord" type="text" class="easyui-validatebox" validType="specialCharFilter('keyWord')" class="easyui-validatebox" type="text"/>
					</td>
					
					<td style="width:10%;text-align:right;" nowrap="nowrap">
						<label for="reportnameQ">发生时间：</label>
					</td>
					<td style="width:15%;text-align:right;" nowrap="nowrap">
						<input id="discoveryTime" type="date" name="discoveryTime"   style="width: 180px"></input>
					</td>
					<td style="width:10%;text-align:right;" nowrap="nowrap">
					</td>
					<td style="width:15%;text-align:right;" nowrap="nowrap">
					</td>
					<td colspan="2" style="width:25%;text-align:right;" nowrap="nowrap">	   
			    		<input type="button" onclick="doQuery()" value="查询" style="background-image: url('${pageContext.request.contextPath}/images/login/search.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;cursor:pointer;"/>	
			    		<input type="button" onclick="resetData()"  value="重置" style="background-image: url('${pageContext.request.contextPath}/images/login/reset.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;margin-right:35px;cursor:pointer"/>			
	    			</td>
	    			
					
				</tr>
			</tbody>
		</table>
	</div>
	 <div data-options="region:'center'"  style="border:#adadad solid 0px;">  
		<table id="problemTab"></table>		
		<div id="problem_toobar" class="etl_panel_title" >
			<a  id="add" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" style="float:left" a>新 增</a>
			<div class="datagrid-btn-separator"></div>
			<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true"  onclick="deleteProblem()">批量删除</a>
		</div>
	</div>
	</form>
</body>
</html>
